<?php

if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval(getvar("gametype"));
$chkGametype = chkGametype($gametype);
if ($chkGametype != 3)
{
    exit();
}
$chk = new CheckMode_3d($curruser['acl'], 5, $gametype);
$chk->checkShow3dPage();
$betname = judge_type($gametype);
unset($chk);
$tblName = $g_gametype_3d[$gametype]['ch'];
if ($curruser['acl'] != 255 || $curruser['prev_id'] != 0)
{
    exit();
}
if ($gametype == 20)
{
    $_5hFlag = true;
}
else
{
    $_5hFlag = false;
}
$ui = new UI_3D(true);
$tpl = new Template2();
$conf = new Config();
require( "class_5h/SRate_5h.php" );
require( "class_5h/SRateTbl_5h.php" );
require( "class_5h/RateConfig_5h.php" );
$SRateTbl = new SRateTbl_5h($gametype);
$show5NStr = "true";
if ($_5hFlag)
{
    $subidArr5H8H = array (1, 2, 3, 4, 5);
}
else
{
    $subidArr5H8H = array (1, 2, 3, 4, 5, 6, 7, 8);
}
$SRate = $SRateTbl;
$RateConfig = new RateConfig_5h($gametype);
$today = date("Y-m-d");
$disk = getvar("disk");
$playtype = getvar("playtype");
$bid = getvar("bid");
$lotot_id = intval(getvar("id"));
if ($lotot_id < 1)
{
    $ui->showErrorPage("错误的期数ID");
    exit();
}
$lottoData = $SRate->getLotto3DById($lotot_id);
if ($lottoData == false)
{
    $ui->showErrorPage("无该期数资料");
    exit();
}
$SRateTbl->sLottoId = $lotot_id;
$fieldArr = array ("method" => "5", "gametype" => $gametype, "round" => $lottoData['round'], "lotto_id" => $lottoData['id'], "betcontent" => "", "orate" => "", "nrate" => "", "pagename" => "1", "paperopen" => $lottoData['open']);
$msg = "";
$disk = $disk == "" ? "a" : $disk;
$playtype = isset($RateConfig->playtypeArr02[$playtype]) ? $playtype : "r1";
$bidstr = "";
if (!$RateConfig->checkDiskType($disk))
{
    diemsg("{$tblName}不合法的盘类{$disk}");
}
$diskIdx = $RateConfig->disk_idx[$disk];
$bid = intval(getvar("bid"));
if (in_array($playtype, $RateConfig->showAllBetArr02))
{
    $bid = 0 < $bid ? $bid : $RateConfig->playGroupArr02[$playtype][0];
    if (!in_array($bid, $RateConfig->playGroupArr02[$playtype]))
    {
        diemsg("{$tblName}玩法资料错误。");
    }
    $bidstr = "&bid=" . $bid;
    $tpl->set("bid", $bid);
}
else
{
    $bidstr = "";
    $bid = 0;
}
if (0 < $bid)
{
    $fieldsArr = array ($bid);
}
else
{
    $fieldsArr = $RateConfig->playGroupArr02[$playtype];
}
$msg = "";
if (in_array($playtype, $RateConfig->showAllSubArr02))
{
    $subFlag = 1;
    $subid = intval(getvar("subid"));
    $subid = 0 < $subid ? $subid : 1;
    if (!isset($RateConfig->subArr[$subid]))
    {
        diemsg("不合法的类别");
    }
}
else
{
    $subFlag = 0;
    $subid = 0;
}
$SRateTbl->subid = $subid;
$alertMsg = "";
if (ispost())
{
    $okI = 0;
    $copyRateOK = intval(getvar("copyRateOK"));
    if (isset($_POST['rebackRateAll']) && $_POST['rebackRateAll'] == "r")
    {
        $erno = $SRate->updateNowRatetoBaseRate($lottoData['id']);
        $fieldArr['betcontent'] = "第" . $lottoData['round'] . " 期 赔率回复";
        $fieldArr['orate'] = "0";
        $fieldArr['nrate'] = "0";
        if (0 < $erno)
        {
            $fieldArr['betcontent'] = "第" . $lottoData['round'] . " 期 赔率回复(x)";
            setRateRecord($fieldArr);
            $alertMsg = "alert('【" . $g_gametype_3d[$gametype]['ch'] . "】第 " . $lottoData['round'] . " 期 基本赔率回复失败, 请重新执行');";
        }
        else
        {
            setRateRecord($fieldArr);
            $alertMsg = "alert('已将【" . $g_gametype_3d[$gametype]['ch'] . "】第 " . $lottoData['round'] . " 期 赔率还回复成基本赔率值');";
        }
    }
    else if ($copyRateOK)
    {
        $errorI = $SRateTbl->copyRateBet($lottoData['id']);
        if (0 < $errorI)
        {
            $msg = $tblName . " :: " . $RateConfig->playtypeArr02[$playtype] . "页面 :: 赔率复制失败";
        }
        else
        {
            $msg = $tblName . " :: " . $RateConfig->playtypeArr02[$playtype] . "页面 :: 赔率复制完成";
            $fieldArr['betcontent'] = $_5hFlag ? "赔率复制(平码1-4及特码赔率同步)" : "赔率复制(球号1-8赔率同步)";
            $fieldArr['orate'] = 0;
            $fieldArr['nrate'] = 0;
            setRateRecord($fieldArr);
        }
        $alertMsg = "alert('{$msg}');";
    }
    else
    {
        $tempStr = "";
        $okI = 0;
        $subIdArr = array (0);
        foreach ($fieldsArr as $val)
        {
            if (in_array($val, $g_betXYArr[$gametype]))
            {
                $xyidArr = array (1, 2);
            }
            else
            {
                $xyidArr = array (0);
            }
            if ($subFlag)
            {
                $subidArr = array ($subid);
            }
            else if (in_array($val, $g_bet4subArr[$gametype]))
            {
                $subidArr = $subidArr5H8H;
            }
            else
            {
                $subidArr = array (0);
            }
            if ($gametype == 24)
            {
                switch ($val)
                {
                    case 0:
                        $subidArr = array ($subid);
                        break;
                    case 3:
                    case 4:
                    case 5:
                        $subidArr = array (0);
                        break;
                    case 6:
                        $subidArr = array (1, 2, 3, 4, 5);
                        break;
                    default:
                        $subidArr = array (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
                        break;
                }
            }
            $betTypeNumber = $RateConfig->getBetTypeNumber($val);
            foreach ($subidArr as $subIdArrKey => $subIdArrVal)
            {
                foreach ($xyidArr as $xyidArrKey => $xyidArrVal)
                {
                    $ratedataArr = array ();
                    $ratedataZeroArr = array ();
                    if ($disk == "a")
                    {
                        $rateBaseArr = $SRate->getRates($lotot_id, $xyidArrVal, 1, $val, $subIdArrVal);
                    }
                    $ratedataZeroArr = $SRate->getRates(0, $xyidArrVal, $diskIdx, $val, $subIdArrVal);
                    foreach ($betTypeNumber as $key2 => $val2)
                    {
                        $rateNum = str_pad($val2, 2, "0", STR_PAD_LEFT);
                        $tempStr = "n_{$val}_{$subIdArrVal}_{$diskIdx}_{$rateNum}_{$xyidArrVal}";
                        $rateIdx = "r" . $rateNum;
                        if (isset($_POST[$tempStr]))
                        {
                            $floatval = min($ratedataZeroArr[$rateIdx], floatval($_POST[$tempStr]));
                            $floatval = 0 < $floatval ? $floatval : "0";
                            $ratedataArr[$rateIdx] = $floatval;
                            if ($disk == "a" && $floatval != $rateBaseArr[$rateIdx])
                            {
                                $tempId = $val . "_" . $subIdArrVal;
                                $fieldArr['betcontent'] = "{$RateConfig->xyidTitle[$xyidArrVal]}[{$betname[$tempId]}]" . $RateConfig->getBetContent($val, $val2);
                                $fieldArr['orate'] = $rateBaseArr[$rateIdx];
                                $fieldArr['nrate'] = $floatval;
                                setRateRecord($fieldArr);
                            }
                            ++$okI;
                        }
                        else
                        {
                            diemsg("更新{$tblName}失败", "玩法资料与内容不齐全，无法更新({$tempStr})", "op.php?op=admin&fp=rate_5h&disk={$disk}&playtype={$playtype}&gametype={$gametype}&id={$lotot_id}");
                        }
                    }
                    $SRate->updateRate($lotot_id, $xyidArrVal, $diskIdx, $val, $subIdArrVal, $ratedataArr);
                }
            }
        }
    }
    if (0 < $okI)
    {
        $msg = $tblName . "&nbsp;::&nbsp;第" . $lottoData['round'] . "期&nbsp;::&nbsp;" . $RateConfig->playtypeArr02[$playtype] . "页面&nbsp;::&nbsp;" . $g_disk_name[$diskIdx] . "&nbsp;::&nbsp;" . "异动成&#21151;  (" . date("Y-m-d H:i:s") . ")";
    }
    else
    {
        $msg = "";
    }
}
$SRateTbl->reloadUrl = "op.php?op=admin&fp=rate_5h&disk={$disk}&playtype={$playtype}{$bidstr}&gametype={$gametype}&subid={$subid}&id={$lotot_id}";
$SRateTbl->subURL = "op.php?op=admin&fp=rate_5h&disk={$disk}&playtype={$playtype}{$bidstr}&gametype={$gametype}&subid={$subid}&id={$lotot_id}";
foreach ($fieldsArr as $val)
{
    if (in_array($val, $g_betXYArr[$gametype]))
    {
        $xyidArr = array (1, 2);
    }
    else
    {
        $xyidArr = array (0);
    }
    if (in_array($val, $g_bet4subArr[$gametype]))
    {
        $subidArr = $subidArr5H8H;
    }
    else
    {
        $subidArr = array (0);
    }
    if ($gametype == 24)
    {
        switch ($val)
        {
            case 0:
                $subidArr = array ($subid);
                break;
            case 3:
            case 4:
            case 5:
                $subidArr = array (0);
                break;
            case 6:
                $subidArr = array (1, 2, 3, 4);
                break;
            default:
                $subidArr = array (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
                break;
        }
    }
    foreach ($xyidArr as $xyidVal)
    {
        foreach ($subidArr as $subidVal)
        {
            $rate_data = $SRate->getRates($lotot_id, $xyidVal, $diskIdx, $val, $subidVal);
            if ($rate_data === false)
            {
                diemsg("查无该期赔率资料");
            }
        }
    }
}
$jslink = "<script> $(function(){ $().chgIptClr(); }); </script>";
$jslink .= "<script src=\"js_3d/showRateRecord.js\"></script>";
$jslink .= "<script src=\"js_3d/js3d.js\"></script>";
$jslink .= "<script src=\"js_3d/jsRate5h.js\"></script>";
$ui->set("jslink", $jslink);
$ui->header();
$disks = "<select onchange=\"location.replace('op.php?op=admin&fp=rate_5h&playtype=" . $playtype . $bidstr . "&subid={$subid}&gametype={$gametype}&id={$lotot_id}&disk='+this.value)\">";
foreach ($g_disk_name as $key => $val)
{
    $chkDisk = $g_disk_code[$key];
    $selectStr = $disk == $chkDisk ? " selected" : "";
    $disks .= "<option value='{$chkDisk}' {$selectStr}>{$val}</option>";
}
$disks .= "</select>";
$playtypeArr = $RateConfig->playtypeArr02;
$playMenu = "";
$playMenuArr = array ();
foreach ($playtypeArr as $key => $val)
{
    if (in_array($key, $RateConfig->showAllBetArr02))
    {
        $bidStrTemp = "&bid=" . $RateConfig->playGroupArr02[$key][0];
    }
    else
    {
        $bidStrTemp = "";
    }
    if ($key == $playtype)
    {
        $playMenuArr[] = "<span class=\"cBig\">{$val}</span>";
    }
    else
    {
        $playMenuArr[] = "<a href=\"op.php?op=admin&fp=rate_5h&gametype={$gametype}&playtype={$key}{$bidStrTemp}&id={$lotot_id}\">{$val}</a>";
    }
}
$playMenu = implode("&nbsp;|&nbsp;", $playMenuArr);
$playMenu .= "&nbsp;&nbsp;◎&nbsp;&nbsp;<a href=op.php?op=admin&fp=history_3d&gametype={$gametype}>回列表</a>&nbsp;◎&nbsp;";
$playMenu .= "<input type=\"button\" value=\"赔率异动纪录\" class=\"nobtnclass\" onclick=\"javascript:showRateRecordPage({$gametype},'" . $lottoData['open'] . "');\"  />";
$g_5number_3dStrTitle = $_5hFlag ? "【４＋１码】" : "【八码】";
echo "<div id=\"divRateRecord\"></div>";
echo title($playtypeArr[$playtype] . " {$g_5number_3dStrTitle}赔率设定-第<b>" . $lottoData['round'] . "</b>期，开奖日期：" . $lottoData['open'] . " " . $disks . " <input type=\"button\" id=\"btnRebackRateAll\" value=\"回复本期赔率\" class=\"nobtnclass\" />", "", "920");
echo title($playMenu, "", "920");
echo $msg == "" ? "" : "<div class='msgBox-yellow' style='width:920px;'>{$msg}</div>";
echo "<br />";
echo "<style> thead, th{font-size:0.9em;} </style>";
echo "<form name='frmSrate' action='op.php?op=admin&fp=rate_5h&disk={$disk}&playtype={$playtype}{$bidstr}&gametype={$gametype}&subid={$subid}' method='post'>";
echo "<input type='hidden' value='{$lotot_id}' name='id' />";
echo $SRateTbl->show_srateTbl($playtype, $disk, $subid, $bid);
echo "</form>";
echo "<span> ※ 快调时, <font style='background-color:#FF9291'>浅红底</font>表示赔率小於 1 </span>";
echo "<br /><span> ※ [<input type='button' class='colorBtnGray' value='- ' /><input type='button' class='colorBtnGray' value='+' />]按钮 每次异动量为<font style='background-color:#FF9291'>0.01</font>" . ( $_5hFlag ? ", 且XY盘同时异动" : "" ) . "，异动後请记得按[确定更改]钮</span>";
echo "<br /><span> ※ {$tblName}玩法，可设定赔率至小数点下第三位。</span>";
echo "</td></tr></table>";
echo "<br />";
echo "<script>";
echo $alertMsg;
echo "$(function(){\r\n  $(\"input#btnRebackRateAll\").click(function(){\r\n    if(confirm(\"确定要将 【" . $g_gametype_3d[$gametype]['ch'] . "】 第" . $lottoData['round'] . " 期 回复成基本赔率值吗(包含所有盘类)?\")){\r\n      $(\"form#frmbtnRebackRateAll\").submit();  \r\n    }\r\n  });\r\n});\r\n</script>\r\n";
echo "<form id=\"frmbtnRebackRateAll\" action=\"op.php?op=admin&fp=rate_5h&disk=" . $disk . "&playtype=" . $playtype . $bidstr . "&gametype=" . $gametype . "&id=" . $lotot_id . "\" method=\"post\"><input type=\"hidden\" value=\"r\" name=\"rebackRateAll\" /></form>";
$ui->footer();
?>